package com.study.zzedu.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.ui.exercise.view.NoScrollGridView;
import com.study.zzedu.utils.Utils;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * 作者：Russell on 2021/1/7 11:16
 */

public class TeachersCourseAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private JSONArray jArray;

    public TeachersCourseAdapter(Context context, JSONArray jsonArray) {
        this.mContext = context;
        this.jArray = jsonArray;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View itemView = LayoutInflater.from(mContext).inflate(R.layout.course_item_option, parent, false);
        return new ContentHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final ContentHolder mholder = (ContentHolder) holder;
        try {
            JSONObject job = jArray.getJSONObject(position);
            mholder.txt_user_xueyuan.setText(Utils.getDefaultStringValue(job,"depart"));
            mholder.name.setText(job.getString("name"));
            mholder.txt_user_zhicheng.setText(Utils.getDefaultStringValue(job,"post"));

            TeachersCourseAdapter2 adapter = new TeachersCourseAdapter2(mContext, job.getJSONArray("course"));
            mholder.gridview.setAdapter(adapter);
        } catch (Exception e) {
            e.toString();
        }
    }

    @Override
    public int getItemCount() {
        return jArray.length();
    }


    public class ContentHolder extends RecyclerView.ViewHolder {
        private TextView txt_user_xueyuan, name, txt_user_zhicheng;
        private NoScrollGridView gridview;
        public ContentHolder(View itemView) {
            super(itemView);
            txt_user_xueyuan = itemView.findViewById(R.id.txt_user_xueyuan);
            name = itemView.findViewById(R.id.txt_user_name);
            txt_user_zhicheng = itemView.findViewById(R.id.txt_user_zhicheng);

            gridview = itemView.findViewById(R.id.gridview);
        }
    }
}